<?php

    extract(extractGet(), EXTR_PREFIX_ALL, 'p');
    
    // name parameter is unique
    if(!$getResultAsArray && isset($p_code)){
        
        /* $project = R::getRow( 'SELECT p.code, p.name, u.name AS po_name, u.lastname AS po_lastname, p.start, p.finish, g.name AS dev_group, p.active
                                            FROM  `project` p
                                                JOIN `group` g 
                                                    ON g.id = p.dev_group
                                                JOIN `user` u
                                                    ON p.product_owner = u.id
                                            WHERE p.code = ? ', array($p_code) ); */
        $project = R::getRow( 'SELECT * FROM project WHERE code = ? ', array($p_code) );
        if(empty($project)){
            
            jsonErrorDie("Project with provided code does not exist.");
            
        } else {
             jsonSuccessDie('project', $project);
        }
    } else {
        /*
        $projects = R::getAll( 'SELECT p.code, p.name, u.name AS po_name, u.lastname AS po_lastname, p.start, p.finish, g.name AS dev_group, p.active
                                            FROM  `project` p
                                                JOIN `group` g 
                                                    ON g.id = p.dev_group
                                                JOIN `user` u
                                                    ON p.product_owner = u.id' ); 
         * 
         */
        $projects = R::getAll( 'SELECT * FROM project');
       
        
        if(!$getResultAsArray){
            jsonSuccessDie('projects', $projects);
        }
    }
